package com.ybkj.o2o.zhuanche.service.impl;

import com.ybkj.o2o.zhuanche.common.query.Car2Query;
import com.ybkj.o2o.zhuanche.common.query.CarQuery;
import com.ybkj.o2o.zhuanche.entity.Car;
import com.ybkj.o2o.zhuanche.entity.CarCriteria;
import com.ybkj.o2o.zhuanche.mapper.BaseMapper;
import com.ybkj.o2o.zhuanche.mapper.CarMapper;
import com.ybkj.o2o.zhuanche.service.CarService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DefaultCarService extends AbstractBaseService<Car, CarCriteria, Long> implements
    CarService {

  @Autowired
  private CarMapper carMapper;

  @Override
  public BaseMapper<Car, CarCriteria, Long> getMapper() {
    return carMapper;
  }

  @Override
  public int insert(Car car) {
    car.setCreated(new Date());
    car.setUpdated(new Date());
    car.setVersion(1L);
    return super.insert(car);
  }

  @Override
  public List<Car> findAll(String appKey) {
    
    return carMapper.findAll(appKey);
  }

  @Override
  public Car findByCarId(Long carId, String appKey) {
    
    return carMapper.findByCarId(carId,appKey);
  }

  @Override
  public int deleteById(Long id, String appKey) {
    
    return carMapper.deleteById(id,appKey);
  }

  @Override
  public int deleteByCarTypeId(Long carTypeId, String appKey) {
    
    return carMapper.deleteByCarTypeId(carTypeId,appKey);
  }

  @Override
  public Car findByNumber(String carNumber, String appKey) {
    
    return carMapper.findByNumber(carNumber,appKey);
  }

  @Override
  public List<Car> findAllByInsuranceTime(Long companyId, String appKey) {
    
    return carMapper.findAllByInsuranceTime(companyId, appKey);
  }

  @Override
  public List<Car> findAllByOverhaulTime(Long companyId, String appKey) {
    
    return carMapper.findAllByOverhaulTime(companyId,appKey);
  }

  @Override
  public Car findByEmployId(Long employId, String appKey) {
    
    return carMapper.findByEmployId(employId,appKey);
  }

  @Override
  public Car queryCarByNumber(String carNumber, String appKey) {
    CarQuery carQuery = new CarQuery();
    carQuery.setCarNumber(carNumber);
    carQuery.setAppKey(appKey);
    List<Car> list = carMapper.selectByParams(carQuery);
    return list != null && list.size() != 0 ? list.get(0) : null;
  }

  @Override
  public List<Car> findByParams(CarQuery carQuery) {
    
    return carMapper.selectByParams(carQuery);
  }

  @Override
  public Long countByParams(CarQuery carQuery) {
    
    return carMapper.countByParams(carQuery);
  }

  @Override
  public List<Car> findByTiaojians(Car2Query car2Query) {
    return carMapper.findByTiaojians(car2Query);
  }

  @Override
  public Long countByTiaojians(Car2Query car2Query) {
    
    return carMapper.countByTiaojians(car2Query);
  }

  @Override
  public Long updateCarTypeId(Long carTypeId, String appKey) {
    return carMapper.updateCarTypeId(carTypeId,appKey);
  }
  
  @Override
  public Long findByRentalCompanyId(Long rentalCompanyId, String appKey) {
    return carMapper.findByRentalCompanyId(rentalCompanyId,appKey);
  }

  @Override
  public int batchCreate(List<Car> carss) {
    int num = 0;
    if (!org.springframework.util.CollectionUtils.isEmpty(carss)) {
      num = carMapper.batchCreate(carss);
    }
    return num;
  }

  @Override public List<Car> findByIds(CarQuery carQuery) {
    return carMapper.findByIds(carQuery);
  }

  @Override public Long countByIds(CarQuery carQuery) {
    return carMapper.countByIds(carQuery);
  }

  @Override
  public List<Car> updateByIds(Long[] ids, String appKey) {
    return carMapper.updateByIds(ids,appKey);
  }

  @Override
  public long count(String appKey) {
    return carMapper.count(appKey);
  }

@Override
public Car queryCarByNumberAndFlights(String carNumber, String flights,
		String appKey) {
	CarQuery carQuery = new CarQuery();
    carQuery.setCarNumber(carNumber);
    carQuery.setFlights(flights);
    carQuery.setAppKey(appKey);
    List<Car> list = carMapper.selectByParams(carQuery);
    return list != null && list.size() != 0 ? list.get(0) : null;
}

@Override
public void updateUpStatus(Long id) {
	carMapper.updateUpStatus(id);
	
} 

}
